#include <QtGui>

#include "sphereDialog.h"
#include "src/vector3d.h"

SphereDialog::SphereDialog(int _id, QWidget *_parent)
    : ObjectDialog(_id, _parent){
    setWindowTitle(QString::fromUtf8("Criando esfera ").append(QString::number(_id)));

    radius = 1;

    createLayout();
}

SphereDialog::~SphereDialog(){
}

void SphereDialog::createLayout(){
    QDoubleSpinBox *radiusDoubleSpinBox = new QDoubleSpinBox();
    radiusDoubleSpinBox->setRange(0, 50.0);
    radiusDoubleSpinBox->setSingleStep(1.0);
    radiusDoubleSpinBox->setValue(radius);
    connect(radiusDoubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(changeRadius(double)));

    QHBoxLayout *radiusLayout = new QHBoxLayout;
    radiusLayout->addWidget(radiusDoubleSpinBox);
    radiusLayout->addStretch(1);

    QGroupBox *radiusGroupBox = new QGroupBox(QString::fromUtf8("Raio"));
    radiusGroupBox->setLayout(radiusLayout);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(radiusGroupBox);
    mainLayout->addLayout(createColorButtonLayout());
    mainLayout->addStretch(1);

    setLayout(mainLayout);
}

void SphereDialog::acceptAndCreate(){

    if(!object){
        object = new Object(id);
        object->makeSphere(radius, Color(colorR / 255.0, colorG / 255.0, colorB / 255.0, colorAlpha / 255.0));
    }
    else if(colorChanged)
    {
        object->setColor(Color(colorR / 255.0, colorG / 255.0, colorB / 255.0, colorAlpha / 255.0));
    }


    emit done(object, SPHERE);
    accept();
}

void SphereDialog::changeRadius(double _r){
    radius = _r;
}
